# -*- coding:utf-8 -*-
import logging
from common.common_config import project_base_dir

format = '[%(asctime)-11s][%(thread)-12s][%(levelname)-8s][%(module)15s:%(lineno)d] %(message)s'


# 配置日志信息
def init_file_log(file_path=f'{project_base_dir}/log.txt', level=logging.DEBUG):
    logging.basicConfig(level=level,
                        format=format,
                        datefmt='%m-%d %H:%M',
                        filename=file_path,
                        filemode='w')


def init_console_log(logger_name="log", level=logging.DEBUG):
    logging.basicConfig(level=level, format=format)
    # 定义一个Handler打印INFO及以上级别的日志到sys.stderr
    console = logging.StreamHandler()
    console.setLevel(level)
    # 设置日志打印格式
    formatter = logging.Formatter(format)
    console.setFormatter(formatter)
    # 将定义好的console日志handler添加到root logger
    logging.getLogger(logger_name).addHandler(console)
